package com.yc.navy.springmvc.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yc.navy.springmvc.bean.ProductInfo;
import com.yc.navy.springmvc.mapper.IProductInfoMapper;
import com.yc.navy.springmvc.service.IProductInfoService;
import com.yc.navy.springmvc.util.ConstantIfo;
import com.yc.navy.springmvc.util.FindByPageParamUtil;

@Service
public class ProductInfoServiceImpl implements IProductInfoService {
	@Autowired
	private IProductInfoMapper productInfoMapper;

	@Override
	public int add(ProductInfo pf) {
		return productInfoMapper.add(pf);
	}

	@Override
	public List<ProductInfo> list(Map<String, Object> map) {
		return productInfoMapper.list(FindByPageParamUtil.changeParam(map));
	}

	@Override
	public ProductInfo get(Long pno) {
		return productInfoMapper.get(pno);
	}

	@Override
	public List<ProductInfo> finds(List<String> pnos) {
		return productInfoMapper.finds(pnos);
	}

	@Override
	public int total(Map<String, Object> map) {
		return productInfoMapper.total(map);
	}

	@Override
	public Map<String, Object> findByFirst(Map<String, Object> map) {
		List<ProductInfo> list = this.list(map);
		if( list == null || list.isEmpty()) {
			return ConstantIfo.emptyMap();
		}
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("goods",list);
		result.put("total", productInfoMapper.total(map));
		return result;
	}
	
}
